<!DOCTYPE html>
<html class="ui-page-login">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>login</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<style>
			.ui-page-login,
			body {
				width: 100%;
				height: 100%;
				margin: 0px;
				padding: 0px;
			}
			.mui-content{height: 100%;}
			.area {
				margin: 20px auto 0px auto;
			}
			
			.mui-input-group {
				margin-top: 10px;
			}
			
			.mui-input-group:first-child {
				margin-top: 20px;
			}
			
			.mui-input-group label {
				width: 22%;
			}
			
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 78%;
			}			
			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}						
			.mui-btn {
				padding: 10px;
			}
			
			.link-area {
				display: block;
				margin-top: 25px;
				text-align: center;
			}			
			.spliter {
				color: #bbb;
				padding: 0px 8px;
			}		
			.oauth-area {
				position: absolute;
				bottom: 20px;
				left: 0px;
				text-align: center;
				width: 100%;
				padding: 0px;
				margin: 0px;
			}			
			.oauth-area .oauth-btn {
				display: inline-block;
				width: 50px;
				height: 50px;
				background-size: 30px 30px;
				background-position: center center;
				background-repeat: no-repeat;
				margin: 0px 20px;
				/*-webkit-filter: grayscale(100%); */
				border: solid 1px #ddd;
				border-radius: 25px;
			}
			
			.oauth-area .oauth-btn:active {
				border: solid 1px #aaa;
			}
			
			.oauth-area .oauth-btn.disabled {
				background-color: #ddd;
			}
			.mui-content{
				background-color:rgb(117,195,235);
			}
			.mui-content-padded{
				margin-top: 30px;
			}
		</style>

	</head>

	<body onload="onloadbody()">
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">登录</h1>			
		</header>
		<div class="mui-content">			
			<div class="mui-content-padded" style="height:55vw;background-image:url(img/log_education.png);background-size: 100%;margin-top: 10px;"></div>			
			<form id='login-form' class="mui-input-group">
				<div class="mui-input-row">
					<label>账号</label>
					<input id='u_username' type="text" class="mui-input-clear mui-input" placeholder="请输入账号" maxlength="16">
				</div>			
				<div class="mui-input-row">
					<label>密码</label>
					<input id='u_password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码" maxlength="16">
				</div>				
				<div class="mui-input-row">	
					<button id="getyzm" type="button" class="mui-btn mui-btn-primary" style="width: 130px;left: 10px;float: left;">
						获取验证码
					</button>
					<input id='yzm' style="width: 50%;float: right;" type="text" class="mui-input-clear mui-input" placeholder="请输入验证码">	
				</div>
			</form>			
			<div class="mui-content-padded">
				
				<button id='login' class="mui-btn mui-btn-block mui-btn-primary">登   录</button>
			
				<div class="link-area">
					<a id='reg'>注册账号</a> 
					<span class="spliter">|</span> 
					<a id='forget_password'>忘记密码</a>
					<span class="spliter">|</span>
					<a id='password_change'>修改密码</a>
				</div>
			</div>
			<div class="mui-content-padded oauth-area">

			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/app.js"></script>
		<script src="js/DHJ.js"></script>
		<script>
			mui.init({
				swipeBack: true //启用右滑关闭功能
			});
			function onloadbody(){
				localStorage.setItem("uid","");
			}
			// 关闭自身窗口
			function closeme(){
				var ws=plus.webview.currentWebview();
				plus.webview.close(ws);
			}
			var uid = "";
			//获取验证码按钮事件
			document.getElementById("getyzm").addEventListener('tap',function(){
				var u_username = document.getElementById("u_username").value;
				var u_pwd = document.getElementById("u_password").value;
				if(u_username.length<1){
					mui.alert("请输入账号");
				}else if(u_pwd.length<1){
					mui.alert("请输入密码")
				}else {
					mui.ajax({
						url:locationIP+'phoneMessageD',
						data:{
							username:u_username,
							pwd:u_pwd
						},
						dataType:'json',
						type:'post',
						success:function(data){
							if(data==0){
								mui.alert('账号或密码错误');
							}else{
								mui.alert('验证码已发送');
							}						
						},
						error: function(xhr,type,errorThrown){
		                mui.toast(type);
		            	}
					});
				};
			});
			//登录按钮事件
			document.getElementById("login").addEventListener('tap',function(){
				var u_username = document.getElementById("u_username").value;
				var u_pwd = document.getElementById("u_password").value;
				var yzm = document.getElementById("yzm").value;
				if(u_username.length<1){
					mui.alert("请输入账号");
				}else if(u_pwd.length<1){
					mui.alert("请输入密码")
				}else if(yzm.length<1){
					mui.alert("请输入验证码")
				}else if(yzm.length<1){
					mui.alert("验证码输入错误")
				}else {
					mui.ajax({
						url:locationIP+'login',
						data:{
							username:u_username,
							pwd:u_pwd,
							yzm:yzm
						},
						dataType:'json',
						type:'post',
						success:function(data){
							//查看获取的数据状态
							console.log(JSON.stringify(data));
							if(data==null){
								mui.alert("账号或密码错误");
							}else{
								//储存用户ID
								uid=data.uId;
								localStorage.setItem("uid",uid);
								//关闭页面
//								plus.webview.close("password_change.html");
//								plus.webview.close("reg.html");
//								plus.webview.close("forget_password.html");
//								closeme();
								//打开新页面将用户ID传过去
								mui.openWindow({
									url:'user_center.html',
									id:'user_center.html',
								});
							};																
						},
						error: function(xhr,type,errorThrown){
			                mui.toast(type);
			            }
					});												
				};				
			});
			//注册账号点击事件
			document.getElementById("reg").addEventListener('tap',function(){
				mui.openWindow({
					url:'reg.html',
					id:'reg.html'				
				});
			});
			//忘记密码点击事件
			document.getElementById("forget_password").addEventListener('tap',function(){
				mui.openWindow({
					url:'forget_password.html',
					id:'forget_password.html'			 	
				});
			});
			//修改密码点击事件
			document.getElementById("password_change").addEventListener('tap',function(){
				mui.openWindow({
					url:'password_change.html',
					id:'password_change.html'				
				});
			});
		</script>
	</body>
</html>